<!-- 实现类似于自定义指令的功能 依赖mark 仅支持点击事件 -->
<template>
	<view class="flex" style="height: 100%;" v-if="!ifButton" @click.stop="clickHandle">
		<slot></slot>
	</view>
	<button v-else><slot></slot></button>
</template>

<script>
import { mapState } from "vuex"
const app = getApp()
export default {
	// 无directive 默认验证登录
	props: ["ifButton","directive","do"],
	computed: mapState({
		userInfo: (state) => state.user.userInfo
	}),
	methods: {
		clickHandle() {
			const handle = this.directive
			if (!handle) {
				if(!this.userInfo) {
					app.toLogin()
					return
				} else this.$emit("do")
			// 一般用不到
			} else handle?.() && this.$emit("do")
		}
	}
}
</script>

<style></style>
